/**
 * 
 */
package com.disys.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * @author Ubaid Raja
 * 
 */
@Entity
@Table(name = "LDAP_USERS")
@NamedQuery(name = "LdapUsers.findUserByUID", query = "select u from LdapUsers u where u.uid = :uid")
public class LdapUsers implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2699022265325971379L;

	public static final String FIND_BY_UID = "LdapUsers.findUserByUID";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Column(unique = true)
	private String uid;
	private String active;
	private String time_added;
	@Enumerated(EnumType.STRING)
	private Role role;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public String getActive() {
		return active;
	}

	public void setActive(String active) {
		this.active = active;
	}

	public String getTime_added() {
		return time_added;
	}

	public void setTime_added(String time_added) {
		this.time_added = time_added;
	}
	
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public boolean isAdmin() {
		return Role.ADMIN.equals(role);
	}

	public boolean isUser() {
		return Role.USER.equals(role);
	}

	@Override
	public int hashCode() {
		return getId();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof LdapUsers) {
			LdapUsers user = (LdapUsers) obj;
			return user.getId() == id;
		}

		return false;
	}
}
